// JavaScript Document
window.onload = function () {
	select();
	Score();
    hander();
}			
// air为airport 机场
// code为三字代码
var air = [];
var code = [];
//index 同步索引；forgetAir 忘记的机场；past 存贮遗忘数组;score 积分。			
var index,ranNum;
var forgetAir = [];			
var past = [];
var score = 0;

function hander() {
	//pra绑定数值改变和提交事件；
	//btn绑定点击事件
	//select绑定数值改变事件
	$("#pra").on({change:verify,
				  submit:verify});
	$(".btn").click(forget);
	$("#select").change(select);
}
    
function randomAir() {
	//随机air索引，符合要求显示。
	ranNum = Math.floor(Math.random() * air.length);
	if ( ($.inArray(ranNum,past) == -1 )&&($.inArray(ranNum,forgetAir) == -1 )) {
		$('.YorN').html("&nbsp;");
		$("#pra").val(null);
	    $(".info").text(air[ranNum]);
	    index = ranNum;
    } else if ((forgetAir.length+past.length) == air.length) {
        changeVal();
    } else {
    	setTimeout("randomAir()",10);
    }
}

function verify() {
	//验证答案
	var val = document.getElementById('pra').value.toUpperCase();
	if (val === code[index]) {
        past.push(ranNum);
        setTimeout("randomAir()",300);
        $('.YorN').html("&nbsp;&#10004;");
        $('.YorN').css("color","green");
        score++;
        Score();
	} else {
        $('.YorN').html("&nbsp;&#10006;");
        $('.YorN').css("color","red");
	}
	
}	

function forget() {
	//没记住的机场
    forgetAir.push(ranNum);
    var content = air[ranNum]+":"+code[ranNum]+"<br>";
    $('.forget').append(content);
    if ((forgetAir.length+past.length) == air.length) {
        changeVal();
        return;
    }
    randomAir();
}

function changeVal() {
	//自动改变
	var n = $('#select').val();
	n ++;
	if (n == 31) {
		n = 0;
	}
	$("#select").val(n);
	select();
}

function init() {
	//数据初始化
	air = [];
	code = [];
	past = [];
	forgetAir = [];
	Score();
}

function Score() {
	//显示积分
    $("#score").text(score);
}

function select() {
	//选择省份
	init();
	var value = $('#select').val();
	switch (parseInt(value)) {
		case 0:
		    air = ["北京首都","北京南苑",
		           "天津滨海",
				   "石家庄正定","秦皇岛山海关","秦皇岛北戴河","邯郸","唐山三女河","张家口",
				   "太原武宿","大同云冈","长治王村","运城关公","五台山","吕梁","临汾",
				   "呼和浩特白塔","海拉尔东山","赤峰土城子","满洲里西郊","乌兰浩特","锡林浩特","二连浩特赛乌苏","包头二里半","通辽","林西","鄂尔多斯","乌海","阿尔山","巴彦卓尔","额济纳旗桃来","左旗巴彦浩特","右旗巴丹吉林","扎兰屯",
				   "上海虹桥","上海浦东",
				   "南京禄口","连云港白塔埠","无锡硕放","常州奔牛","徐州观音","盐城南洋","南通兴东","苏州光福","淮安涟水","扬州泰州",
				   "杭州萧山","宁波栎社","温州龙湾","舟山普陀山","台州(黄岩)路桥","衢州","义乌",
				   "济南遥墙","青岛流亭","威海大水泊","烟台蓬莱","临沂","潍坊","东营永安","济宁曲阜",
				   "福州长乐","厦门高崎","泉州晋江","龙岩连城","武夷山",
				   "南昌昌北","赣州黄金","九江庐山","景德镇罗家","宜春明月山","井冈山",
				   "合肥新桥","黄山屯溪","安庆天柱山","阜阳西关","池州九华山",
				   "沈阳桃仙","大连周水子","锦州湾","丹东浪头","朝阳","长海",
				   "长春龙嘉","吉林二台子","延吉朝阳川","通化三源浦","长白山",
				   "哈尔滨太平","齐齐哈尔三家","佳木斯","牡丹江海浪","黑河","大庆萨尔图","依兰","鸡西兴凯","漠河古莲","大兴安岭加格达奇","伊春林都",
				   "西安咸阳","汉中关西","延安二十里铺","榆林榆阳","安康五里",
				   "兰州中川","敦煌","嘉峪关","庆阳","天水","金昌","张掖",
				   "西宁曹家堡","格尔木",
				   "银川河东","中卫","固原六盘山",
				   "乌鲁木齐地窝堡","阿克苏","喀什","伊宁","塔城","库车","且末","和田","库尔勒","那拉提","吐鲁番","富蕴","阿勒泰","哈密","克拉玛依","喀纳斯","博乐",
				   "广州新白云","深圳宝安","珠海金湾","揭阳潮汕","湛江","梅州梅县","佛山","兴宁",
				   "南宁吴玗","桂林两江","柳州白莲","北海福城","梧州长洲岛","百色田阳",
				   "海口美兰","三亚凤凰","西沙永兴岛","博鳌",
				   "武汉天河","宜昌三峡","荆州沙市","襄阳(襄樊)刘集","恩施许家坪","十堰武当山",
				   "长沙黄花","张家界荷花","常德桃花源","永州零陵","怀化芷江","衡阳南岳",
				   "郑州新郑","洛阳北郊","南阳姜营","安阳",
				   "重庆江北","万州五桥","黔江舟白",
				   "成都双流","泸州蓝田","九寨沟黄龙","攀枝花保安营","南充高坪","宜宾五粮液","绵阳南郊","西昌青山","广元盘龙","达州河市","广汉","康定",
				   "昆明长水","丽江三义","德宏芒市","保山","迪庆香格里拉","景洪西双版纳嘎洒","文山普者黑","大理","普洱(思茅)","临沧","昭通","腾冲",
				   "贵阳龙洞堡","铜仁大兴","安顺黄果树","兴义","黎平","遵义新舟","荔波","毕节飞雄","凯里黄平","六盘水月",
				   "拉萨贡嘎","昌都邦达","林芝米林","阿里昆莎"];
            code = ["PEK","NAY",
					"TSN",
					"SJW","SHP","BPE","HDG","TVS","ZQZ",
					"TYN","DAT","CIH","YCU","WUT","LLV","LFQ",
					"HET","HLD","CIF","NZH","HLH","XIL","ERL","BAV","TGO","LXI","DSN","WUA","YIE","RLK","EJN","AXF","RHT","NZL",
					"SHA","PVG",
					"NKG","LYG","WUX","CZX","XUZ","YNZ","NTG","SZV","HIA","YIY",
					"HGH","NGB","WNZ","HSN","HYN","JUZ","YIW",
					"TNA","TAO","WEH","YNT","LYI","WEF","DOY","JNG",
					"FOC","XMN","JIN","LCX","WUS",
					"KHN","KOW","JIU","JDZ","YIC","JGS",
					"HFE","TXN","AQG","FUG","JUH",
					"SHE","DLC","JNZ","DDG","CHG","CNI",
					"CGQ","JIL","YNJ","TNH","NBS",
					"HRB","NDG","JMU","MDG","HEK","DQA","YLN","JXA","OHE","JGD","LDS",
					"SIA/XIY","HZG","ENY","UYN","AKA",
					"LHW","DNH","JGN","IQN","THQ","JIC","YZY",
					"XNN","GOQ",
					"INC","ZHY","GYU",
					"URC","AKU","KHG","YIN","TCG","KCA","IQM","HTN","KRL","NLT","TLQ","FYN","AAT","HMI","KRY","KJI","BRL",
					"CAN","SZX","ZUH","SWA","ZHA","MXZ","FUO","XIN",
					"NNG","KWL","LZH","BHY","WUZ","AEB",
					"KAK","SYX","YXG","BAR",
					"WUH","YIH","SHS","XFN","ENH","WDS",
					"CSX","DYG","CGD","LLF","HJJ","HNY",
					"CGO","LYA","NNY","AYN",
					"CKG","WXN","JIQ",
					"CTU","LZO","JZH","PZI","NAO","YBP","MIG","XIC","GYC","DAX","GHN","KGT",
					"KMG","LJG","LUM","BSD","DIG","JHG","WNH","DLU","SYM","LNJ","ZAT","TCZ",
					"KWE","TEN","AVA","ACX","HZH","ZYI","LLB","BFJ","KJH","LPF",
					"LXA","BPX","LZY","NGQ"];
		    break;
		case 1:
		    air = ["北京首都","北京南苑"];
            code = ["PEK","NAY"];
		    break;
		case 2:
		    air = ["天津滨海"];
            code = ["TSN"];
		    break;
		case 3:
		    air = ["石家庄正定","秦皇岛山海关","秦皇岛北戴河","邯郸","唐山三女河","张家口"];
            code = ["SJW","SHP","BPE","HDG","TVS","ZQZ"];
		    break;
		case 4:
		    air = ["太原武宿","大同云冈","长治王村","运城关公","五台山","吕梁","临汾"];
            code = ["TYN","DAT","CIH","YCU","WUT","LLV","LFQ"];
		    break;
		case 5:
		    air = ["呼和浩特白塔","海拉尔东山","赤峰土城子","满洲里西郊","乌兰浩特","锡林浩特","二连浩特赛乌苏","包头二里半","通辽","林西","鄂尔多斯","乌海","阿尔山","巴彦卓尔","额济纳旗桃来","左旗巴彦浩特","右旗巴丹吉林","扎兰屯"];
            code = ["HET","HLD","CIF","NZH","HLH","XIL","ERL","BAV","TGO","LXI","DSN","WUA","YIE","RLK","EJN","AXF","RHT","NZL"];
		    break;
		case 6:
		    air = ["上海虹桥","上海浦东"];
            code = ["SHA","PVG"];
		    break;
		case 7:
		    air = ["南京禄口","连云港白塔埠","无锡硕放","常州奔牛","徐州观音","盐城南洋","南通兴东","苏州光福","淮安涟水","扬州泰州"];
            code = ["NKG","LYG","WUX","CZX","XUZ","YNZ","NTG","SZV","HIA","YIY"];
		    break;
		case 8:
		    air = ["杭州萧山","宁波栎社","温州龙湾","舟山普陀山","台州(黄岩)路桥","衢州","义乌"];
            code = ["HGH","NGB","WNZ","HSN","HYN","JUZ","YIW"];
		    break;
		case 9:
		    air = ["济南遥墙","青岛流亭","威海大水泊","烟台蓬莱","临沂","潍坊","东营永安","济宁曲阜"];
            code = ["TNA","TAO","WEH","YNT","LYI","WEF","DOY","JNG"];
		    break;
		case 10:
		    air = ["福州长乐","厦门高崎","泉州晋江","龙岩连城","武夷山"];
            code = ["FOC","XMN","JIN","LCX","WUS"];
		    break;
		case 11:
		    air = ["南昌昌北","赣州黄金","九江庐山","景德镇罗家","宜春明月山","井冈山"];
            code = ["KHN","KOW","JIU","JDZ","YIC","JGS"];
		    break;
		case 12:
		    air = ["合肥新桥","黄山屯溪","安庆天柱山","阜阳西关","池州九华山"];
            code = ["HFE","TXN","AQG","FUG","JUH"];
		    break;
		case 13:
		    air = ["沈阳桃仙","大连周水子","锦州湾","丹东浪头","朝阳","长海"];
            code = ["SHE","DLC","JNZ","DDG","CHG","CNI"];
		    break;
		case 14:
		    air = ["长春龙嘉","吉林二台子","延吉朝阳川","通化三源浦","长白山"];
            code = ["CGQ","JIL","YNJ","TNH","NBS"];
		    break;
		case 15:
		    air = ["哈尔滨太平","齐齐哈尔三家","佳木斯","牡丹江海浪","黑河","大庆萨尔图","依兰","鸡西兴凯","漠河古莲","大兴安岭加格达奇","伊春林都"];
            code = ["HRB","NDG","JMU","MDG","HEK","DQA","YLN","JXA","OHE","JGD","LDS"];
		    break;
		case 16:
		    air = ["西安咸阳","汉中关西","延安二十里铺","榆林榆阳","安康五里"];
            code = ["SIA/XIY","HZG","ENY","UYN","AKA"];
		    break;
		case 17:
		    air = ["兰州中川","敦煌","嘉峪关","庆阳","天水","金昌","张掖"];
            code = ["LHW","DNH","JGN","IQN","THQ","JIC","YZY"];
		    break;
		case 18:
		    air = ["西宁曹家堡","格尔木"];
            code = ["XNN","GOQ"];
		    break;
		case 19:
		    air = ["银川河东","中卫","固原六盘山"];
            code = ["INC","ZHY","GYU"];
		    break;
		case 20:
		    air = ["乌鲁木齐地窝堡","阿克苏","喀什","伊宁","塔城","库车","且末","和田","库尔勒","那拉提","吐鲁番","富蕴","阿勒泰","哈密","克拉玛依","喀纳斯","博乐"];
            code = ["URC","AKU","KHG","YIN","TCG","KCA","IQM","HTN","KRL","NLT","TLQ","FYN","AAT","HMI","KRY","KJI","BRL"];
		    break;
		case 21:
		    air = ["广州新白云","深圳宝安","珠海金湾","揭阳潮汕","湛江","梅州梅县","佛山","兴宁"];
            code = ["CAN","SZX","ZUH","SWA","ZHA","MXZ","FUO","XIN"];
		    break;
		case 22:
		    air = ["南宁吴玗","桂林两江","柳州白莲","北海福城","梧州长洲岛","百色田阳"];
            code = ["NNG","KWL","LZH","BHY","WUZ","AEB"];
		    break;
		case 23:
		    air = ["海口美兰","三亚凤凰","西沙永兴岛","博鳌"];
            code = ["KAK","SYX","YXG","BAR"];
		    break;
		case 24:
		    air = ["武汉天河","宜昌三峡","荆州沙市","襄阳(襄樊)刘集","恩施许家坪","十堰武当山"];
            code = ["WUH","YIH","SHS","XFN","ENH","WDS"];
		    break;
		case 25:
		    air = ["长沙黄花","张家界荷花","常德桃花源","永州零陵","怀化芷江","衡阳南岳"];
            code = ["CSX","DYG","CGD","LLF","HJJ","HNY"];
		    break;
		case 26:
		    air = ["郑州新郑","洛阳北郊","南阳姜营","安阳"];
            code = ["CGO","LYA","NNY","AYN"];
		    break;
		case 27:
		    air = ["重庆江北","万州五桥","黔江舟白"];
            code = ["CKG","WXN","JIQ"];
		    break;
		case 28:
		    air = ["成都双流","泸州蓝田","九寨沟黄龙","攀枝花保安营","南充高坪","宜宾五粮液","绵阳南郊","西昌青山","广元盘龙","达州河市","广汉","康定"];
            code = ["CTU","LZO","JZH","PZI","NAO","YBP","MIG","XIC","GYC","DAX","GHN","KGT"];
		    break;
		case 29:
		    air = ["昆明长水","丽江三义","德宏芒市","保山","迪庆香格里拉","景洪西双版纳嘎洒","文山普者黑","大理","普洱(思茅)","临沧","昭通","腾冲"];
            code = ["KMG","LJG","LUM","BSD","DIG","JHG","WNH","DLU","SYM","LNJ","ZAT","TCZ"];
		    break;
		case 30:
		    air = ["贵阳龙洞堡","铜仁大兴","安顺黄果树","兴义","黎平","遵义新舟","荔波","毕节飞雄","凯里黄平","六盘水月"];
            code = ["KWE","TEN","AVA","ACX","HZH","ZYI","LLB","BFJ","KJH","LPF"];
		    break;
		case 31:
		    air = ["拉萨贡嘎","昌都邦达","林芝米林","阿里昆莎"];
            code = ["LXA","BPX","LZY","NGQ"];
		    break;
	}
	randomAir();
}